import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

const path = require('path')
import themePreprocessorPlugin from "@zougt/vite-plugin-theme-preprocessor";

export default defineConfig({
  plugins: [
    vue(),
    themePreprocessorPlugin({
      less: {
        // 各个主题文件的位置
        multipleScopeVars: [
          {
            scopeName: "theme-default",
            path: path.resolve("src/theme/default.less"),
          },
          {
            scopeName: "theme-green",
            path: path.resolve("src/theme/green.less"),
          },
        ],
      },
    }),
  ],
  // 开启less支持
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true
      }
    }
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      '@':path.resolve(__dirname, 'src')
    }
  },
  server: {
    port: 3001,// 配置端口号
    open: true,// 在服务器启动时自动在浏览器中打开应用程序
    cors: true,// 默认启用并允许任何源
    proxy: {
      '/api': {
        target:"http://localhost:3000", //代理接口
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
})
